﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BusinessLogic;
using System.Data;
using System.Data.SqlClient;

namespace DataAccessLogic
{
    public static class ServiceTotalListDataAccess
    {
        public static ServiceTotalList GetServiceReportTotalList(Guid serviceReportID)
        {
            ServiceTotalList stl = null;

            if (serviceReportID != Guid.Empty)
            {
                List<SqlParameter> parms = new List<SqlParameter>();
                parms.Add(new SqlParameter("@SERVICEREPORTID", serviceReportID));

                DataTable dt = DataAccess.Get(StoredProcedures.USP_SERVICETOTAL_GETBYSERVICEREPORTID, parms);

                if (dt != null)
                {
                    stl = new ServiceTotalList();

                    foreach (DataRow row in dt.Rows)
                    {
                        ServiceTotal st = new ServiceTotal();
                        st.ID = DataAccess.CheckForGuidColumn(row, "ID");
                        st.Date = DataAccess.CheckForDateTimeColumn(row ,"DATE");
                        st.Labor = DataAccess.CheckForDecimalColumn(row, "LABOR");
                        st.Mileage = DataAccess.CheckForDecimalColumn(row, "MILEAGE");
                        st.Other = DataAccess.CheckForDecimalColumn(row ,"OTHER");
                        st.Travel = DataAccess.CheckForDecimalColumn(row, "TRAVEL");
                        st.OtherDescription = DataAccess.CheckForStringColumn(row, "OTHERDESCRIPTION");

                        stl.Add(st);
                    }
                }
            }

            return stl;
        }
    }
}